// @flow
import React from 'react';
import { Table } from 'antd';
import BaseComponent from '../common/BaseComponent';
import { PaginationConfig } from '_antd@3.6.6@antd/lib/table';

interface IProps{
  dataSource: object[],
  pagination?:PaginationConfig
}

class ObjectkeysTable extends BaseComponent<IProps, any> {
  public render() {
    const columns = Object.keys(this.props.dataSource[0] || {}).map((key) => {
      return {
        title: key,
        dataIndex: key,
        key,
      };
    });
    return (
      <Table
        pagination={this.props.pagination}
        columns={columns}
        style={{ ...this.props.style }}
        dataSource={this.props.dataSource}
      />);
  }
}

export default ObjectkeysTable
